package com.sxt.demo.djiapplication.dji

import dji.common.mission.waypoint.Waypoint
import dji.common.mission.waypoint.WaypointAction
import dji.common.mission.waypoint.WaypointActionType

class WayPoint(
    /**
     * 纬度
     */
    val latitude: Double,

    /**
     * 经度
     */
    val longitude: Double,

    /**
     * 到达位点后是否需要拍照
     */
    var needTakePic: Boolean,

    /**
     * 高度
     */
    altitude: Float,

    /**
     * 速度
     */
    speed: Float,

    /**
     * 位点顺序
     */
    val order: Int
) {
    val wayPoint: Waypoint = Waypoint(latitude, longitude, altitude)

    init {
        wayPoint.speed = speed
        if (needTakePic) {
            // 到达位点后做的事情
            setTakePicActionOnWayPoint()
        }
    }

    fun setAltitude(altitude: Float) {
        wayPoint.altitude = altitude
    }

    fun getAltitude(): Float {
        return this.wayPoint.altitude
    }

    fun setSpeed(speed: Float) {
        this.wayPoint.speed = speed
    }

    fun getSpeed(): Float {
        return this.wayPoint.speed
    }

    @JvmName("_setNeedTakePic")
    fun setNeedTakePic(need: Boolean) {
        if (need) {
            setTakePicActionOnWayPoint()
        } else {
            this.wayPoint.waypointActions = null
        }
        needTakePic = need
    }

    private fun setTakePicActionOnWayPoint() {
        wayPoint.waypointActions = listOf(
            // 对焦
            WaypointAction(WaypointActionType.CAMERA_FOCUS, 1000),
            // 拍照
            WaypointAction(WaypointActionType.START_TAKE_PHOTO, 3000)
        )
    }

}
